import {
	userLogin, //用户登录
	userLogout, //用户登出
	getVersion,//版本号
	sms,//短信
	forgetPassword,//忘记密码
	banner,
	privacy, //获取隐私协议
} from '@/api/loginApi'
import {
	getStore,
	setStore
} from '@/util/service'
const login = {
	namespaced: true,
	state: {
		token: getStore('token') || '',
		role: getStore('role') || '',
		userInfo: getStore('userInfo') || {}
	},
	getters: {},
	mutations: {
		SET_TOKEN: (state, params) => {
			state.token = params;
			setStore('token', params);
		},
		SET_ROLE: (state, params) => {
			state.role = params;
			setStore('role', params);
		},
		SET_USERINFO: (state, params) => {
			state.userInfo = params;
			setStore('userInfo', params);
		}
	},
	actions: {
		//用户登录
		UserLogin({
			state,
			commit,
			dispatch
		}, params) {
			return new Promise((resolve, reject) => {
				userLogin(params).then(res => {
					resolve(res)
				})
			})
		}, 
		//用户登出
		UserLogout({
			state,
			commit,
			dispatch
		}, params) {
			return new Promise((resolve, reject) => {
				userLogout(params).then(res => {
					resolve(res)
				})
			})
		},
		//版本号
		GetVersion({
			state,
			commit,
			dispatch
		}, params) {
			return new Promise((resolve, reject) => {
				getVersion(params).then(res => {
					resolve(res)
				})
			})
		},
		//短信
		Sms({
			state,
			commit,
			dispatch
		}, params) {
			return new Promise((resolve, reject) => {
				sms(params).then(res => {
					resolve(res)
				})
			})
		},
		//忘记密码
		GorgetPassword({
			state,
			commit,
			dispatch
		}, params) {
			return new Promise((resolve, reject) => {
				forgetPassword(params).then(res => {
					resolve(res)
				})
			})
		},
		//轮播图
		Banner({
			state,
			commit,
			dispatch
		}, params) {
			return new Promise((resolve, reject) => {
				banner(params).then(res => {
					resolve(res)
				})
			})
		},
		//获取隐私协议
		Privacy({
			state,
			commit,
			dispatch
		}, params) {
			return new Promise((resolve, reject) => {
				privacy(params).then(res => {
					resolve(res)
				})
			})
		},
	}
}
export default login
